package cn.laoma.thread1.t1_003;

import lombok.SneakyThrows;

import java.util.concurrent.TimeUnit;

/**
 * @program: ThreadDemos
 * @description: 锁定当前对象,同步方法和非同步方法是够可以同时运行？
 * @author: 老马
 * @create: 2021-01-23 16:04
 **/
public class Sync03Test {
    @SneakyThrows
    public static void main(String[] args) {
        Sync03 s3 = new Sync03();
        Thread t1 = new Thread(s3::addCount);
        //第一次查询没有获得结果
        Thread t2 = new Thread(s3::getCount);
        TimeUnit.NANOSECONDS.sleep(10);
        //过会再查就获得结果了
        new Thread(s3::getCount).start();
        t1.start();
        t2.start();
        try {
            t1.join();
            t2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }


}
